#include "Game.h"

Game::Game()
{
	m_game_state = GS_SELECT_PLANETS;
}
Game::Game(int p_player_cap)
{
	m_player_cap = p_player_cap;
	m_game_state = GS_SELECT_PLANETS;
}
Game::~Game()
{
}


Player* Game::getPlayerFromObject(Object *p_kaka)
{
	for(unsigned int i = 0; i < m_players.size(); i++)
	{
		if(m_players.at(i)->getPlanet() == p_kaka)
		{
			return m_players.at(i);
		}
	}

	return NULL;
}
int Game::getNumberPlayers()
{
	return m_players.size();
}
Player* Game::getPlayer(unsigned int p_index)
{
	if(p_index < m_players.size())
	{
		//printf("returning player %d\n", (int)m_players[p_index]);
		return m_players[p_index];
	}

	printf("no player to return\n");
	printf("m_players.size() = %d\n", m_players.size());
	return NULL;
}
const std::vector<Player*>& Game::getPlayers()
{
	return m_players;
}
int Game::getPlayerSpotsLeft()
{
	return m_player_cap - getNumberPlayers();
}
game_state_t Game::getState()
{
	return m_game_state;
}


void Game::setState(game_state_t p_state)
{
	m_game_state = p_state;
}


bool Game::addPlayer(Player *p_player)
{
	if(getNumberPlayers() >= m_player_cap)
	{
		return false;
	}

	m_players.push_back(p_player);

	if(getPlayerSpotsLeft() <= 0)
	{
		setState(GS_PLAYING);
	}

	return true;
}


void Game::restart()
{
	Player::reset();
	m_players.clear();
	m_game_state = GS_SELECT_PLANETS;
}
